﻿using System;

namespace MyOrganizer.Pages
{
    public partial class AccountInfo : MyOrganizerModel.PlatformModel
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                LoadReports();
            }
            catch (Exception ex)
            {
                MyOrganizerModel.LoggingModel.Log(MyOrganizerModel.ConstantsModel.LogMode, ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            try
            {
                Logic.ChangePassword(txtOldPass.Value, txtNewPass.Value, UserId);
                txtOldPass.Value = string.Empty;
                txtNewPass.Value = string.Empty;
            }
            catch (Exception ex)
            {
                MyOrganizerModel.LoggingModel.Log(MyOrganizerModel.ConstantsModel.LogMode, ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        protected void btnChangeUser_Click(object sender, EventArgs e)
        {
            try
            {
                Logic.ChangeUsername(txtOldUser.Value, txtNewUser.Value, UserId);
                txtOldUser.Value = string.Empty;
                txtNewUser.Value = string.Empty;
            }
            catch (Exception ex)
            {
                MyOrganizerModel.LoggingModel.Log(MyOrganizerModel.ConstantsModel.LogMode, ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        protected void btnReport_Click(object sender, EventArgs e)
        {
            try
            {
                MyOrganizerModel.Database.Reports Report = new MyOrganizerModel.Database.Reports();
                Report.UserId = UserId;
                Report.ReportType = ddlReportType.SelectedValue;
                Report.State = "Active";
                Report.Message = txtReport.Value;
                Report.CreatedDate = DateTime.Now;
                Logic.AddReport(Report);
                txtReport.Value = string.Empty;
                LoadReports();
            }
            catch (Exception ex)
            {
                MyOrganizerModel.LoggingModel.Log(MyOrganizerModel.ConstantsModel.LogMode, ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        private void LoadReports()
        {
            rptData.DataSource = Logic.GetReportsByUserId(UserId);
            rptData.DataBind();
        }
    }
}